import { asBlob } from 'html-docx-js-typescript-modify'
import { downloadFile } from '../download'
import docxDefaultConfig from '@/config/docx-default-config'

/**
 *  @deprecated
 *
 * 生成的格式规范有误， 使用 docx.js 生成
 * pureRictTextToBlob
 */
export async function createDocxDocument(text: string): Promise<Blob> {
  return (await asBlob(text, {
    ...docxDefaultConfig.a4
  })) as Blob
}

/**
 * @deprecated
 *
 * 生成的格式规范有误， 使用 docx.js 生成
 * pureRichTextExportDocx 代替导出
 */
export async function exportDocxDocument(
  text: string,
  filename?: string,
  prefix = '.docx'
) {
  try {
    const _filename = filename || new Date().getTime().toString()
    const blob = await createDocxDocument(text)
    downloadFile(URL.createObjectURL(blob), `${_filename}${prefix}`)
  } catch (error) {
    return
  }
}
